package com.itheima.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//设置虚拟路径
@WebServlet("/cun")
public class CunServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("这里是一个存钱的servlet ");
        //把钱存到servletContext中 因为它代表web项目
        //它代表web项目 存到这个里面 是不是就存到了web项目中
        // 那么只要在web项目中的servlet就可以获取
        // 怎么获取到ServletContext对象呢？ 告诉大家 servlet有个方法
        ServletContext servletContext = getServletContext();
        //  因为父类中有这个功能！！！
        servletContext.setAttribute("money",1000000);

        System.out.println("存钱完毕");

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("cun le 1000000块钱");

    }
}
